import os
import time
import datetime
import logging

path = "../log"


class LogModel(object):
    def __init__(self, address=None):
        if not os.path.exists(path):
            os.makedirs(path)
        self.fammer = logging.Formatter(style='{', fmt='{asctime}: {levelname}: {filename}: {lineno}: {message}')
        self.address = address

    def get_log(self):
        loger = logging.getLogger("die")
        loger.setLevel("DEBUG")
        a = logging.StreamHandler()
        a.setLevel("DEBUG")

        a.setFormatter(self.fammer)
        if self.address == None:
            b = logging.FileHandler(path + "/%s.log" % str(datetime.date.today()))
        else:
            b = logging.FileHandler(path + "/%s_%s.log" % (self.address, str(datetime.date.today())))
        b.setLevel("DEBUG")
        b.setFormatter(self.fammer)
        loger.addHandler(a)
        loger.addHandler(b)
        return loger


if __name__ == '__main__':
    LogModel()
